package cn.kgc.tangcco.pojo;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author 李昊哲
 * @Description
 * @create 2021/1/16 17:10
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Accessors(chain = true)
@Table(name = "course")
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
public class Course implements Serializable {

    private static final long serialVersionUID = -2025898822269898785L;
    /**
     * 学科编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /**
     * 学科名称
     */
    @Column(name = "name")
    private String name;

    public Course(String name) {
        this.name = name;
    }

    public Course(String name, List<Stu> stus) {
        this.name = name;
        this.stus = stus;
    }

    /**
     * 该学科内的学生列表
     * joinColumns当前类的主键
     * inverseJoinColumns关联对象的主键
     * mappedBy不可与JoinTable和JoinColumn一同使用
     */
    // @JsonBackReference
    @ManyToMany(targetEntity = Stu.class,fetch = FetchType.LAZY)
    @JoinTable(
            name = "sc",
            joinColumns = {@JoinColumn(name = "cid",referencedColumnName = "id")},
            inverseJoinColumns = @JoinColumn(name = "sid",referencedColumnName = "id"))
    private List<Stu> stus;
}
